package cn.itcast.hotel;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;


public class Demo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 线程开启之后需要执行里面的call方法
        MyCallable1 mc = new MyCallable1();

        // Thread t1 = new Thread(mc);

        // 可以获取线程执行完毕之后的结果.也可以作为参数传递给Thread对象
        FutureTask<String> ft = new FutureTask<>(mc);

        // 创建线程对象
        Thread t1 = new Thread(ft);

        // String s = ft.get();
        // 开启线程
        t1.start();
//new Thread(new FutureTask<>(new MyCallable1())).start();
        String s = ft.get();
        System.out.println(s);
    }
}
class MyCallable1 implements Callable<String> {
    @Override
    public String call() throws Exception {
        for (int i = 0; i < 10; i++) {
            System.out.println("跟女孩表白" + i);
        }
        // 返回值就表示线程运行完毕之后的结果
        return "答应";
    }
}